package stream;


import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-06-16
 * Time: 9:23
 */
public class Main {
    public static void main(String[] args) {
        int arr[] = {9,8,7,6,5,4,3,2,1};
        quickSort(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    private static void quickSort(int[] arr, int left, int right) {
        if(left>=right) {
            return ;
        }
        int pai = partition(arr, left, right);
        quickSort(arr,left,pai-1);
        quickSort(arr,pai+1,right);
    }

    private static int partition(int[] arr, int left, int right) {
        int tmp = arr[left];
        while(left < right){
            while( left < right && arr[right]>=tmp){
                right--;
            }
            arr[left] = arr[right];
            while(left < right && arr[left]<=tmp){
                left++;
            }
            arr[right] = arr[left];
        }
        arr[left] = tmp;
        return left;
    }
}
